<?php

/*

  Action	$5

  +1 Card; +1 Action; +$1
  When you discard this from play, if you didn’t buy a Victory card this turn, you may put this on top of your deck.

 */

class Treasury extends Card implements iAction, iKingdom, iSeaside {

    public function __construct() {
        parent::__construct("Treasury", 5);
        $this->undoPlay = false;
        $this->undoBuy = true;
    }

    public function getDescription() {
        return array(
            "+1 Card",
            "+1 Action",
            "+$1",
            "When you discard this from play, if you didn’t buy a Victory card this turn, you may put this on top of your deck.");
    }
    
    public function play(Game $game, $isRealCard) {
        $game->addActions(1);
        $drawed_cards = $game->drawCards(1);
        $game->addMoney(new Price(1));
         ScreenDisplay::addScreenMessage($game, true, "get +1 action, +1$  and draw " . nicePrint($drawed_cards), "+1 action, +1$ and draws " . sizeof($drawed_cards) . " cards");
		 $game->cardActionFinished();
        return true;
    }

    public function cleanup(Game $game) {

        $boughtCards = $game->getBoughtCards();
        $victory_bought = false;
        foreach ($boughtCards as $card) {
            if ($card instanceof iVictory) {
                $victory_bought = true;
                break;
            }
        }

        if (!$victory_bought) {

            $options = array(new Option(1, "Yes"), new Option(2, "No"));
            $output = MySocket::GetUserReply($game, Input_ChooseOne, $options, 1, 1, null, "Return treasury on top of the draw deck?");
            $answer = $output[0];
            if ($answer == "Yes") {
                $game->moveCardFromPileToPile($this, PlayArea, DrawPile);
                 ScreenDisplay::addScreenMessage($game, true, "return ".  nicePrint($this)." on top of your deck ", "returns ".ScreenDisplay::$LMSG." on top of his deck");
            } else {
                $game->moveCardFromPileToPile($this, PlayArea, DiscardPile);
            }
        }
        $game->cardCleanupFinished();
    }

}

?>